package com.two.service.pinglun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.two.common.entity.Pinglun;
import com.two.common.util.CommonResult;
import com.two.service.pinglun.mapper.PinglunMapper;
import com.two.service.pinglun.service.PinglunService;
import com.two.service.pinglun.vo.PinglunVo;
import com.two.service.pinglun.vo.SayVo;
import com.two.service.pinglun.vo.SelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PinglunServiceImpl extends ServiceImpl<PinglunMapper, Pinglun> implements PinglunService {
   @Autowired
   private PinglunMapper pinglunMapper;

    @Override
    public CommonResult findAll(Integer currentPage, Integer pageSize, SelectVo selectVo,Integer rid,Integer roleid) {
//        Page<Pinglun> page = new Page<>(currentPage, pageSize);
//           QueryWrapper<Pinglun> queryWrapper=new QueryWrapper<>();
//           if (StringUtils.hasText(pinglunVo.getRestaurantname())){
//               queryWrapper.like("restaurantname",pinglunVo.getRestaurantname());
//           }
//        Page<Pinglun> pinglunPage = pinglunMapper.selectPage(page, queryWrapper);
//           return new CommonResult(2000,"查询成功",pinglunPage);
            PageHelper.startPage(currentPage,pageSize);
        System.out.println("qqqqq"+selectVo.getRestaurantName());
        System.out.println("11111111");
        List<Pinglun> list = pinglunMapper.selectByRidAndUid(selectVo,rid,roleid);
        PageInfo<Pinglun> pageInfo=new PageInfo<Pinglun>(list);
        Map map=new HashMap();
        map.put("pageInfo",pageInfo);
        map.put("roleid",roleid);
        return new CommonResult(2000,"查询成功",map);
    }

    @Override
    public CommonResult del(Integer id) {
         pinglunMapper.deleteById(id);
        return new CommonResult(2000,"删除成功",null);
    }

    @Override
    public CommonResult insert( PinglunVo pinglunVo) {
        Pinglun pinglun=new Pinglun();
        Date date=new Date();
        pinglun.setSaytime(date);
        pinglun.setIsDeleted(0);
        pinglun.setDishName(pinglunVo.getDishName());
        pinglun.setRid(pinglunVo.getRid());
        pinglun.setUsermonicker(pinglunVo.getUsermonicker());
        pinglun.setSay(pinglunVo.getComment());
        pinglunMapper.insert(pinglun);
        return new CommonResult(2000,"添加成功",null);
    }

    @Override
    public CommonResult add(Pinglun pinglun) {
        pinglunMapper.insert(pinglun);
        return new CommonResult(2000,"添加成功",null);
    }

    @Override
    public CommonResult find(String dishName, Integer rid) {
         List<Pinglun> list= pinglunMapper.selectByusermonicker(dishName,rid);
        return new CommonResult(2000,"查询成功",list);
    }
}
